package anthology.daily_question._24_12;

public class _0999可以被一步捕获的棋子数 {
    class Solution {
        private static final int [][] DIRS = {{1,0},{0,1},{-1,0},{0,-1}};
        public int numRookCaptures(char[][] board) {
            final int SIZE = 8;
            int x0 = 0, y0 = 0;
            for(int i = 0; i < SIZE; i++){
                for(int j = 0; j < SIZE; j++){
                    if(board[i][j] == 'R'){
                        x0 = i;
                        y0 = j;
                        break;
                    }
                }
            }
            int count = 0;
            for(int[] d : DIRS){
                int x = x0 + d[0];
                int y = y0 + d[1];
                while (0 <= x && x < SIZE && 0 <= y && y < SIZE && board[x][y] == '.') {
                    x += d[0];
                    y += d[1];
                }
                if (0 <= x && x < SIZE && 0 <= y && y < SIZE && board[x][y] == 'p') {
                    count++;
                }
            }
            return count;
        }
    }
}
